(function() {
  var DataSources, MyFormView, MyView,
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };

  MyView = require('./my_view');

  DataSources = require('dataaccess/data_sources');

  module.exports = MyFormView = (function(_super) {

    __extends(MyFormView, _super);

    MyFormView.name = 'MyFormView';

    function MyFormView() {
      this.subscribeToDataSourceEvents = __bind(this.subscribeToDataSourceEvents, this);

      this.subscribeToControlsEvents = __bind(this.subscribeToControlsEvents, this);

      this.deleteModel = __bind(this.deleteModel, this);

      this.saveModel = __bind(this.saveModel, this);

      this.getDeleteButtonName = __bind(this.getDeleteButtonName, this);

      this.getSaveButtonName = __bind(this.getSaveButtonName, this);
      return MyFormView.__super__.constructor.apply(this, arguments);
    }

    MyFormView.prototype.getSaveButtonName = function() {
      return null;
    };

    MyFormView.prototype.getDeleteButtonName = function() {
      return null;
    };

    MyFormView.prototype.initialize = function() {
      return MyFormView.__super__.initialize.apply(this, arguments);
    };

    MyFormView.prototype.render = function() {
      console.debug('WineDetailsView#render', this, this.$el);
      $(this.containerSelector).html(this.$el);
      return MyFormView.__super__.render.apply(this, arguments);
    };

    MyFormView.prototype.saveModel = function() {
      var src,
        _this = this;
      console.debug(this.id + '#saveModel-Start');
      this.updateModelFromView();
      if (!this.model.isNew()) {
        this.model.save();
      } else {
        src = DataSources.GetWines();
        this.model.url = src.url;
        this.model.save().done(function(response) {
          return src.create(response);
        }).fail(function(response) {
          return _this.model.dispose();
        });
      }
      return console.debug(this.id + '#saveModel-End');
    };

    MyFormView.prototype.deleteModel = function() {
      console.debug(this.id + '#deleteWine-Start');
      this.model.destroy();
      return console.debug(this.id + '#deleteWine-End');
    };

    MyFormView.prototype.updateModelFromView = function() {
      return null;
    };

    MyFormView.prototype.subscribeToControlsEvents = function() {
      this.delegate('click', this.getSaveButtonName(), this.saveModel);
      return this.delegate('click', this.getDeleteButtonName(), this.deleteModel);
    };

    MyFormView.prototype.subscribeToDataSourceEvents = function() {
      return this.modelBind('destroy', this.remove);
    };

    return MyFormView;

  })(MyView);

}).call(this);
